package map;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",99);
        map.put("数学",93);
        map.put("英语",90);
        map.put("物理",92);
        map.put("化学",94);
        map.put("政治",97);
        System.out.println(map);


        Set<String> keySet = map.keySet();
        /*for (String key: keySet
             ) {
            System.out.println("key"+key);
        }*/
//        keySet.forEach( System.out::println);
     /*   keySet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/
        keySet.forEach(e-> System.out.println(e));
        /*在Lambda表达式中，如果参数与调用方法传入的参数一致时，可以简写为方法引用：e->对象.方法(e)*;
        可以写为
        对象::方法
         */
        keySet.forEach(System.out::println);
       /* map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s+":"+integer);
            }
        });*/
        map.forEach((k,v)-> System.out.println(k+":"+v));

        Set<Map.Entry<String,Integer>> entries = map.entrySet();

        for (Map.Entry<String,Integer> e : entries){
            String key = e.getKey();
            Integer value = e.getValue();
            System.out.println(key+":"+value);
        }

        Collection<Integer> values = map.values();
        for (Integer value: values
             ) {
            System.out.println("value:"+value);
        }
    }
}
